<template>
    

  <el-dialog
    :title="'好友验证'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    
     <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      
      style="width: 100%;">
      
      <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" >
     
      
      
 <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="200"
        label="操作">
         <template slot-scope="scope">
             <span slot="footer" class="dialog-footer">
        <el-select  placeholder="请选择"  v-model="state[scope.row.id]" style="width:100px">
    <el-option
    
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
      <el-button type="primary" @click="dataFormSubmit(scope.row.id)">确定</el-button>
    </span>
        
        </template> 
      </el-table-column>
       <el-table-column
        prop="username"
        header-align="center"
        align="center"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="mobile"
        header-align="center"
        align="center"
        label="电话号码">
      </el-table-column>
      <el-table-column
        prop="friMsg"
        header-align="center"
        align="center"
        label="验证消息">
      </el-table-column> 
      <el-table-column
        prop="friTime"
        header-align="center"
        align="center"
        width="200"
        label="请求时间">
      </el-table-column> 
      </el-form>
    </el-table>




    
   
    
    
  </el-dialog>
</template>

<script>
  export default {
  
    data () {
      
      return {
        visible: false,
        dataForm: {
         
        
          username:'',
          mobile:'',
          friMsg: '',
          friTime:'',
        
        },
         options: [{
          value: 2,
          label: '同意'
        }, {
          value: 3,
          label: '拒绝'
        }],
        state: {},
        
        dataList: [],
        dataListLoading:false,
        
      }
    },


  mounted () {
    this.dataList.forEach(item => {
      this.$set(this.state, item.id, '') // 父、  子、  子的赋值
    })
  },

    methods: {
    //       changeSelect (id) {
    //   console.log(id, this.state[id])
    // },
      init () {
        
        this.visible = true
        this.$http({
          url: this.$http.adornUrl('/generator/friends/msgList'),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
             
            this.dataList = data.list
          } else {
            this.dataList = []
            
          }
          this.dataListLoading = false
        })
       
      },
      // 表单提交
      dataFormSubmit (id) {
        //console.log(id,this.state[id])
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/friends/updateState`),
              method: 'post',
              params: this.$http.adornParams({
                'friSender': id,
                'friState': this.state[id]
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    // this.visible = false
                    this.init()
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
